package com.shelpe.services.sinbad.entity.mongo;

import java.util.Date;

import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import com.shelpe.services.sinbad.entity.jpa.User;

import lombok.Data;

@Data
@Document(collection = "account_balance")
public class AccountBalance {
	
	@Id
	private String id;
	
	@Indexed
	private long userID;
	
	private float balance;
	
	@Indexed
	private Date createTime;
	
	public void from(User user) {
		this.userID = user.getUserID();

		this.createTime = new Date();
		this.id = DateFormatUtils.format(this.createTime, "yyyyMMdd") + "_" + this.userID;
	}
}
